author-pic

Tomohiro Nagasaka

テキストファイル処理


Published on April 01, 2020

ファイル読み込み

import io
f = io.open(str(readpath), mode="r", encoding="utf-8")
strs = f.read()
f.close()

行ごとにリストに変換

lines = strs.split("\n")

ファイル書き込み

f = io.open(writepath, mode="w", encoding="utf-8")
for line in lines:
    f.writelines(line + "\n")
f.close()

If you like it, share it!